import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import Login from '@/components/Login.vue'
import ShowTime from '@/components/ShowTime.vue'

const routes = [
  { path: '/', name: 'Home', component: Home },
  { path: '/login', name: 'Login', component: Login },
  {path:'/showTime',name:'ShowTime',component: ShowTime}
  // ...existing routes...
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 可选：导航守卫，未登录重定向到登录页
router.beforeEach((to, from, next) => {
  const publicPages = ['/login']
  const authRequired = !publicPages.includes(to.path)
  const token = localStorage.getItem('jwt_token')
  if (authRequired && !token) {
    return next('/login')
  }
  next()
})

export default router